﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="EditCustomAdminPage.aspx.cs" Inherits="Cms.Web.UI.Admin.EditCustomAdminPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script language="javascript" type="text/javascript" src="Admin/edit_area/edit_area_loader.js"></script>
    <script language="javascript" type="text/javascript" src="Admin/Js/Edit.js"></script>
    <script language="javascript" type="text/javascript">
        //<![CDATA[
        $(document).ready(function () {
            cms.Edit.ShowTabOverlays();
        });

        var codeEditorLoaded = false;
        var xmlTranslationsEditorLoaded = false;

        function editorLoaded(id) {
            if (id == "txtCode")
                codeEditorLoaded = true;
            if (id == "txtXmlTranslations")
                xmlTranslationsEditorLoaded = true;
            if (codeEditorLoaded && xmlTranslationsEditorLoaded) {
                editAreaLoader.setValue("txtXmlTranslations", originalXmlTranslations);
                editAreaLoader.setValue("txtCode", originalCode);
                cms.Edit.HideTabOverlays();
            }
            if (document.getElementById("ctl00_body_pnlProperties").style.display == "")
                document.getElementById("ctl00_body_txtName").focus();
            if (document.getElementById("ctl00_body_pnlXmlTranslations").offsetLeft >= 0) {
                editAreaLoader.toggle("txtXmlTranslations");
                editAreaLoader.toggle("txtXmlTranslations");
            }
            if (document.getElementById("ctl00_body_pnlCode").offsetLeft >= 0) {
                editAreaLoader.toggle("txtCode");
                editAreaLoader.toggle("txtCode");
            }
        }

        editAreaLoader.init({
            id: "txtXmlTranslations",
            syntax: "xml",
            start_highlight: true,
            allow_resize: "no",
            allow_toggle: false,
            toolbar: "undo,redo,change_smooth_selection,reset_highlight,highlight,syntax_selection",
            word_wrap: true,
            replace_tab_by_spaces: 4,
            EA_load_callback: "editorLoaded"
        });

        editAreaLoader.init({
            id: "txtCode",
            syntax: "cpp",
            start_highlight: true,
            allow_resize: "no",
            allow_toggle: false,
            toolbar: "undo,redo,change_smooth_selection,reset_highlight,highlight,syntax_selection",
            word_wrap: true,
            replace_tab_by_spaces: 4,
            EA_load_callback: "editorLoaded"
        });

        function updateCode() {
            txtXmlTranslations = document.getElementById("txtXmlTranslations");
            txtCode = document.getElementById("txtCode");
            txtXmlTranslations.value = editAreaLoader.getValue("txtXmlTranslations");
            document.getElementById("ctl00_body_hidXmlTranslations").value = txtXmlTranslations.value;
            txtCode.value = editAreaLoader.getValue("txtCode");
            document.getElementById("ctl00_body_hidCode").value = txtCode.value;
        }

        function setCodeEditorHeight() {
            var viewportHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
            var xmlTranslationsContainer = document.getElementById("xmlTranslationsContainer");
            var codeContainer = document.getElementById("codeContainer");
            var xmlTranslationsHeight = viewportHeight - iLib.Pos.FindY(xmlTranslationsContainer) - 65;
            xmlTranslationsHeight = xmlTranslationsHeight < 100 ? 100 : xmlTranslationsHeight;
            xmlTranslationsContainer.style.height = xmlTranslationsHeight + "px";
            var codeHeight = viewportHeight - iLib.Pos.FindY(codeContainer) - 65;
            codeHeight = codeHeight < 100 ? 100 : codeHeight;
            codeContainer.style.height = codeHeight + "px";
        }

        function updatePanels(tab) {
            var pnlProperties = document.getElementById("ctl00_body_pnlProperties");
            var pnlXmlTranslations = document.getElementById("ctl00_body_pnlXmlTranslations");
            var pnlCode = document.getElementById("ctl00_body_pnlCode");
            pnlProperties.style.display = "none";
            var width = pnlXmlTranslations.offsetWidth;
            pnlXmlTranslations.style.position = "absolute";
            pnlXmlTranslations.style.left = -10000 + "px";
            pnlXmlTranslations.style.width = width + "px";
            pnlXmlTranslations.style.top = "0px";
            pnlCode.style.position = "absolute";
            pnlCode.style.left = -10000 + "px";
            pnlCode.style.width = width + "px";
            pnlCode.style.top = "0px";
            switch (tab) {
                case "properties":
                    pnlProperties.style.display = "";
                    break;
                case "xmlTranslations":
                    pnlXmlTranslations.style.position = "";
                    pnlXmlTranslations.style.width = "100%";
                    pnlXmlTranslations.style.left = "0px";
                    break;
                case "code":
                    pnlCode.style.position = "";
                    pnlCode.style.width = "100%";
                    pnlCode.style.left = "0px";
                    break;
            }
        }

        var txtFilename;
        var txtName;
        var txtXmlTranslations;
        var txtCode;

        var originalFilename;
        var originalName;
        var originalXmlTranslations;
        var originalCode;
        var originalSelectedAllowedAdminGroups;
        var originalSelectedDeniedAdminGroups;

        function init() {
            setCodeEditorHeight();
            txtFilename = document.getElementById("ctl00_body_txtFilename");
            txtName = document.getElementById("ctl00_body_txtName");
            txtXmlTranslations = document.getElementById("txtXmlTranslations");
            txtCode = document.getElementById("txtCode");
            originalFilename = txtFilename.value;
            originalName = txtName.value;
            originalXmlTranslations = document.getElementById("ctl00_body_hidXmlTranslations").value;
            originalCode = document.getElementById("ctl00_body_hidCode").value;
            editAreaLoader.setValue("txtXmlTranslations", originalXmlTranslations);
            editAreaLoader.setValue("txtCode", originalCode);
            originalSelectedAllowedAdminGroups = cms.Edit.GetSelectedCheckboxValues("ctl00_body_tdAllowedAdminGroups");
            originalSelectedDeniedAdminGroups = cms.Edit.GetSelectedCheckboxValues("ctl00_body_tdDeniedAdminGroups");
        }

        function isDirty() {
            var value = originalFilename == "" || originalName == "" ||
	                    originalFilename != txtFilename.value ||
	                    originalName != txtName.value ||
            	        originalXmlTranslations != txtXmlTranslations.value ||
	                    originalCode != txtCode.value ||
	                    originalSelectedAllowedAdminGroups != cms.Edit.GetSelectedCheckboxValues("ctl00_body_tdAllowedAdminGroups") ||
	                    originalSelectedDeniedAdminGroups != cms.Edit.GetSelectedCheckboxValues("ctl00_body_tdDeniedAdminGroups");
            document.getElementById("ctl00_tabs_hidIsDirty").value = value;
            return value;
        }
	    //]]>
	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="buttons" runat="server">
    <asp:UpdatePanel ID="upnlButtons" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:LinkButton ID="lbSave" runat="server" OnClick="lbSave_Click" CssClass="orangeButton" OnClientClick="isDirty(); updateCode();"><span id="lblSave1" runat="server"><span id="lblSave2" runat="server"><img id="imgSave" runat="server" src="Admin/Img/icons/disk.png" alt="" /><span id="lblSave3" runat="server"><cms:LocalizedLiteral ID="llSave" runat="server" /></span></span></span></asp:LinkButton>
            <asp:LinkButton ID="lbSaveAndReturn" runat="server" OnClick="lbSaveAndReturn_Click" CssClass="orangeButton" OnClientClick="isDirty(); updateCode();"><span id="Span1" runat="server"><span id="Span2" runat="server"><img id="img1" runat="server" src="Admin/Img/icons/disk.png" alt="" /><span id="Span3" runat="server"><cms:LocalizedLiteral ID="llSaveAndReturn" runat="server" /></span></span></span></asp:LinkButton>
            <asp:hyperlink ID="hlCancel" runat="server" navigateUrl="Admin/CustomAdminPages.aspx" CssClass="orangeButton"><span id="lblCancel1" runat="server"><span id="lblCancel2" runat="server"><img id="imgCancel" runat="server" src="Admin/Img/icons/delete.png" alt="" /><span id="lblCancel3" runat="server"><cms:LocalizedLiteral ID="llCancel" runat="server" /></span></span></span></asp:hyperlink>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="tabs" runat="server">
    <asp:UpdatePanel ID="upnlTabs" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <cms:AdminTabStrip ID="tabStrip" runat="server" SelectedValue="properties" OnChange="tabStrip_Click">
                <cms:AdminTabItem ID="tiProperties" runat="server" value="properties" EnabledImage="Admin/Img/icons/page_gear.png"><cms:LocalizedLiteral ID="llPropertiesTab" runat="server" /></cms:AdminTabItem>
                <cms:AdminTabItem ID="tiCode" runat="server" value="code" EnabledImage="Admin/Img/icons/page_white_csharp.png"><cms:LocalizedLiteral ID="llCodeTab" runat="server" /></cms:AdminTabItem>
                <cms:AdminTabItem ID="tiXmlTranslations" runat="server" value="xmlTranslations" EnabledImage="Admin/Img/icons/page_white_world.png"><cms:LocalizedLiteral ID="llXmlTranslationsTab" runat="server" /></cms:AdminTabItem>
            </cms:AdminTabStrip>
            <input type="hidden" id="hidIsDirty" runat="server" />
            <input type="hidden" id="hidSave" runat="server" />
            <input type="hidden" id="hidPageID" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="body" runat="server">
    <asp:Literal ID="litIcon" runat="server" Visible="false" Text="Admin/Img/Icons/page_white_visualstudio.png" />

    <asp:Panel ID="pnlCode" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlCode" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <input type="hidden" id="hidCode" runat="server" />
                <input type="hidden" id="hidSaveCode" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <div id="codeContainer" style="height: 400px;">
            <textarea id="txtCode" cols="10" rows="10" style="width: 100%; height: 100%;"></textarea>
        </div>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>
    
    <asp:Panel ID="pnlXmlTranslations" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlXmlTranslations" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <input type="hidden" id="hidXmlTranslations" runat="server" />
                <input type="hidden" id="hidSaveXmlTranslations" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <div id="xmlTranslationsContainer" style="height: 400px;">
            <textarea id="txtXmlTranslations" cols="10" rows="10" style="width: 100%; height: 100%;"></textarea>
        </div>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>
    
    <asp:Panel ID="pnlProperties" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlProperties" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llName" runat="server" />:</td>
                        <td><asp:TextBox ID="txtName" runat="server" /></td>
                        <td><cms:LocalizedLiteral ID="llFilename" runat="server" />:</td>
                        <td>
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="padding-right: 4px;"><asp:TextBox ID="txtFilename" runat="server" /></td>
                                    <td><strong>.aspx</strong></td>
                                </tr>
                            </table>
                        </td>
                        <td>
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="padding-right: 4px;"><asp:CheckBox ID="chkShowInMenu" runat="server" /></td>
                                    <td><cms:LocalizedLiteral ID="llShowInMenu" runat="server" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <span class="editFormSubheader"><cms:LocalizedLiteral ID="llAdministratorAccessControlHeader" runat="server" /></span>
                <table class="editForm">
                    <tr id="trAllowedAdministratorGroups" runat="server" valign="top">
                        <td style="width: 250px;"><cms:LocalizedLiteral ID="llAllowedAdministratorGroups" runat="server" />:</td>
                        <td id="tdAllowedAdminGroups"><cms:AdministratorGroupSelector id="gsAllowedAdministratorGroups" runat="server" ShowTabOverlay="true" /></td>
                    </tr>
                    <tr id="trDeniedAdministratorGroups" runat="server" valign="top">
                        <td><cms:LocalizedLiteral ID="llDeniedAdministratorGroups" runat="server" />:</td>
                        <td id="tdDeniedAdminGroups"><cms:AdministratorGroupSelector id="gsDeniedAdministratorGroups" runat="server" ShowTabOverlay="true" /></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>

    <script language="javascript">
        //<![CDATA[
        iLib.Dom.AddListener(window, "load", init);
        cms.Ajax.Init();
        cms.Ajax.AddEndRequestHandler(function () {
            editAreaLoader.setValue("txtXmlTranslations", document.getElementById("ctl00_body_hidXmlTranslations").value);
            editAreaLoader.setValue("txtCode", document.getElementById("ctl00_body_hidCode").value);
            cms.Edit.HideTabOverlays();
            if (document.getElementById("ctl00_body_pnlProperties").style.display == "")
                document.getElementById("ctl00_body_txtName").focus();
            if (document.getElementById("ctl00_body_pnlXmlTranslations").offsetLeft >= 0) {
                editAreaLoader.toggle("txtXmlTranslations");
                editAreaLoader.toggle("txtXmlTranslations");
            }
            if (document.getElementById("ctl00_body_pnlCode").offsetLeft >= 0) {
                editAreaLoader.toggle("txtCode");
                editAreaLoader.toggle("txtCode");
            }
        });
        //]]>
    </script>
</asp:Content>
